package model

import "encoding/json"

// Server 服务器
type Server struct {
	Ip         string `json:"ip" gorm:"type:varchar(128);column:ip;comment:'服务器IP'"`
	Port       int    `json:"port" gorm:"type:int;column:port;comment:'服务器端口'"`
	Username   string `json:"username" gorm:"type:varchar(128);column:username;comment:'服务器用户名'"`
	Password   string `json:"password" gorm:"type:varchar(128);column:password;comment:'服务器密码'"`
	PrivateKey string `json:"privateKey" gorm:"type:varchar(256);column:private_key;comment:'私钥'"`
	OsType     string `json:"osType" gorm:"type:varchar(128);column:os_type;comment:'操作系统类型'"`
	BaseModel
}

// Credential 凭证
type Credential struct {
	Name       string `json:"name" gorm:"type:varchar(128);column:name;comment:'凭证名称'"`
	UserName   string `json:"userName" gorm:"type:varchar(128);column:user_name;comment:'凭证用户名'"`
	Password   string `json:"password" gorm:"type:varchar(128);column:password;comment:'凭证密码'"`
	PrivateKey string `json:"privateKey" gorm:"type:varchar(256);column:private_key;comment:'私钥'"`
	BaseModel
}

// Resource 资源
type Resource struct {
	BaseModel
	Name        string          `json:"name" gorm:"type:varchar(128);column:name;comment:'资源名称'"`
	Description string          `json:"description" gorm:"type:varchar(255);column:description;comment:'资源描述'"`
	Type        int8            `json:"type" gorm:"type:tinyint(4);column:type;comment:'资源类型'"`
	Meta        json.RawMessage `json:"meta" gorm:"type:json;column:meta;comment:'元数据'"`
}

// K8sCluster k8s集群
type K8sCluster struct {
	BaseModel
	Cluster string `json:"cluster" gorm:"type:varchar(128);column:cluster"`
	Config  string `json:"config" gorm:"type:varchar(256);column:config"`
}

type ResourceUser struct {
	ResourceId   uint64 `json:"resourceId" gorm:"type:bigint(20) unsigned;column:resource_id;comment:'资源ID'"`
	UserId       uint64 `json:"userId" gorm:"type:bigint(20) unsigned;column:user_id;comment:'用户ID'"`
	ResourceType int8   `json:"resourceType" gorm:"comment:'资源类型'"`
}

type ResourceRole struct {
	ResourceId   uint64 `json:"resourceId" gorm:"type:bigint(20) unsigned;column:resource_id;comment:'资源ID'"`
	RoleId       uint64 `json:"roleId" gorm:"type:bigint(20) unsigned;column:role_id;comment:'角色ID'"`
	ResourceType int8   `json:"resourceType" gorm:"comment:'资源类型'"`
}
